/*
 * Project: util-root
 * 
 * File Created at 2014-10-08
 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.zx.callback.common.enums;

import java.io.Serializable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 响应码对照表
 *
 * @author mr
 * @version V1.0
 * @since 2014-10-08 11:24
 */
public enum MessageEnumTable implements Serializable {
    //系统级
    SYS__999(-999, "后台验证出错"),
    //系统级
    SYS_10001(10001, "系统错误"),

    LOCK_FAIL(-200, "锁定失败"),
    GATEWAY_FAIL(-210, "网关调用失败"),
    PASSWORD_NO_SET(-220, "未设置密码"),
    PASSWORD_FAIL(-221, "密码错误"),
    PAY_PARAM_ERROR(-222, "支付客户端参数错误"),
    PAY_NOT_SUPPORT_WAP(-223, "暂不支持手机网页支付"),
    PAY_ALREADY(-224, "当前订单已支付"),
    PAY_GENERATE_WATER_NO_ERROR(-225, "支付生成第三方交易流水号失败"),
    PAY_NOT_SUPPORT_CLIENT(-226, "支付生成第三方交易流水号失败"),
    PAY_ERROR(-227, "支付失败"),
    PAY_NOT_SUPPORT_WECHAT(-228, "暂不支持微信支付支付"),
    PAY_SIGN_ERROR(-229, "签名验证失败"),
    PAY_APP_ID_ERROR(-230, "支付appId 不匹配"),
    PAY_ORDER_NOT_EXIST(-231, "支付订单不存在"),
    PAY_UPDATE_PAY_TABLE_STATE_ERROR(-232, "修改支付第三方交易订单表的状态失败"),

    //服务 [000]-[099]
    SUCCESS(0, "成功!"),
    EXCEPTION(1, "处理发生异常"),
    ERROR(2, "失败."),
    INSERT_SQL(3, "数据插入异常！"),
    UPDATE_SQL(4, "数据更新异常！"),
    DELETE_SQL(5, "删除失败"),
    UPDATE_FAILED(6,"未找到更新数据"),
    PARAM_ERROR(7, "参数错误"),
    GET_DATA_ERROR(8,"未找到数据"),
    MOBILE_FORMAT_ERROR(9,"手机格式不正确"),
    ADD_COUNT_LIMIT(10,"增加次数已达到上限"),
    TOKEN_IS_NULL(11,"Token为空"),
    TOKEN_IS_OUT_TIME(12,"Token已过期"),
    NONE_PERMISSION(13,"数据无权限操作"),
    DATA_EXIST(14,"数据存在"),
    PUSH_SESSION_FAIL(15,"推送session失败"),
    REQUEST_WRONG(16, "系统请求不合法"),
    INFORM_FAIL(17, "下单成功通知管理失败"),

    USER_NOT_EXIST(1000, "用户信息不存在"),
    USER_PWD_ERROR(1001, "密码错误"),
    USER_OR_PWD_ERROR(1002, "用户名或者密码不正确"),
    USER_ALREADY_DISABLE(1003, "用户名被禁用"),
    USER_ALREADY_OVERDUE(1004, "用户名已过期"),

    LACK_OF_INTEGRAL(2000, "积分不足"),

    ORDER_NOT_EXIST(5000, "订单不存在"),
    ORDER_STATE_ERROE(5001, "订单状态不符合"),
    ORDER_NOT_BELONG_TO_USER(5002, "订单不属于当前用户"),
    ORDER_ALREDY_EXPIRY(5003, "订单已过期"),

    PASSENGER_EXIST(1201, "该旅客信息已经存在。"),
    PASSENGER_ADD_ERROR(1202, "添加旅客信息失败。"),
    PASSENGER_UPDATE_ERROR(1203, "修改旅客信息失败。"),
    COUPON_NOT_EXIST(1204, "优惠卷不存在。"),
    COUPON_ALREADY_USE(1205, "优惠卷已经使用。"),
    COUPON_NOT_SUPPORT(1206, "该优惠卷不能用于支付购票票款。"),
    COUPON_ALREDY_EXPIRY(1207, "优惠卷已经过期。"),
    PASSENGER_NOT_EXIST(1208, "该旅客信息不存在。"),
    PASSENGER_ERROR_STATE(1209, "该旅客状态不正确。"),
    JUHE_API_ERROR(1210, "调用第三方接口异常。"),
    JUHE_API_IDCARD_NOT_EXIST(1211, "该乘客信息不匹配。"),
    IDCARD_NAME_NOT_MATCHING(1212, "姓名和身份证信息不匹配。"),
    ;


    /**
     * 存放CODE -> Enum的Map
     */
    private static final ConcurrentMap<Integer, MessageEnumTable> CODE_MAP = new ConcurrentHashMap<Integer, MessageEnumTable>(
            MessageEnumTable.values().length);

    /**
     * 填充CODE --> Enum的Map
     */
    static {
        for (MessageEnumTable messageEnumTable : MessageEnumTable.values()) {
            CODE_MAP.put(messageEnumTable.code, messageEnumTable);
        }
    }

    /**
     * 响应码
     */
    private final int code;

    /**
     * 响应消息
     */
    private final String message;

    /**
     * 构造函数
     *
     * @param code    响应码
     * @param message 响应消息
     */
    MessageEnumTable(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public MessageEnumTable fromCode(Integer code) {
        return CODE_MAP.get(code);
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static String getMessage(String msg, String ...messages){
        int count = 0;
        if(messages != null && messages.length > 0){
            for (String str : messages) {
                count++;
                msg = msg.replaceAll("%"+count+"S", str);
            }
        }
        return msg;
    }

}
